package com.chenu.gamscriptman.compoent;

import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;

/**
 * @author flyan
 * date 2019-12-24
 * @function MD5加密匹配例程，用于Spring Security完成密码验证
 */
public class ChenuMD5PasswordEncoder implements PasswordEncoder {

    /* md5加密例程，它没有匹配方法 */
    private Md5PasswordEncoder md5;


    public ChenuMD5PasswordEncoder() {
        md5 = new Md5PasswordEncoder();
    }

    /* 加密 */
    @Override
    public String encode(CharSequence rawPassword) {
        return md5.encodePassword(String.valueOf(rawPassword), "chenu");
    }

    /* 匹配密码 */
    @Override
    public boolean matches(CharSequence rawPassword, String encodePassword) {
        return md5.encodePassword(String.valueOf(rawPassword), "chenu")
                .equals(encodePassword);
    }

}
